<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "南航明珠商城-商品列表"> </@frame.head>
<script type="text/javascript">
var path="${contextPath}";
</script>
<script type="text/javascript" src="${contextPath}/resources/js/tool/ckeditor/ckeditor.js"></script>
<div class="page-container">
<form id="upda" action="${contextPath}/courses/uploadFile"
		method="post" enctype="multipart/form-data">
    
     <video id="my-video" class="video-js" controls preload="auto"
			width="400" height="400" poster="m.jpg" data-setup="{}">
	        <source src="${webPath}/videofile/${courses.video}">
	 </video>
        <span class="btn-upload form-group">
                <input class="input-text upload-url radius" type="text"
			id="uploadfile-1" readonly>
                    <a href="" class="btn btn-primary radius">
                     <i class="iconfont">&#xf0020;</i>浏览视频</a>
                <input name="file" type="file" class="input-file"
			onchange="choiceMusicAndVideo(this)">
        </span>
         <input class="btn btn-primary radius" onclick="videoSubmit()"
			type="text" value="提交">
</form>
	<form action="${contextPath}/courses/course_update" method="post"
		class="form form-horizontal" id="jvForm" enctype="multipart/form-data">
 <input type="hidden" name="fileName" id="fileVideoName" value="">
  <input type="hidden" name="coursesId" id="coursesId" value="${courses.id?c}">
		<div id="file_size"
			style="width: 400px; border-bottom: 1px solid #C0C0C0;"></div>
		<br />

		<div>
        <tr>
            <td width="20%">
                <span>*</span>
                上传图片(90x150尺寸):</td>
                <td width="80%">
                 注:该尺寸图片必须为90x150。
                </td>
        </tr>

                <tr>
                 <td width="20%"></td>
                    <td width="80%">
                        <img src="${webPath}/img/${courses.imge}" width="100" height="100" id="allUrl" />
                        <!-- 在选择图片的时候添加事件，触发Ajax异步上传 -->
                        <input name='pic' type="file" value="${courses.imge}"
					onchange="imgee(this)" />
                     </td>
                </tr>
        </div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				课程标题：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" placeholder=""
					id="coursetitle" name="coursetitle" value="${courses.coursetitle}">
			</div>
		</div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				课程副标题：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" placeholder=""
					id="coursetitleTwo" name="coursetitleTwo"
					value="${courses.coursetitle}">
			</div>
		</div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				讲师姓名：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" placeholder="" id="teacher"
					name="teacher" value="${courses.teacher}">
			</div>
		</div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				艺术专业：</label>
			<div class="formControls col-xs-6 col-sm-6">
			  <#list coursesType as list>
			<div class="radio-box">
					<input type="radio"  name="courseTypeOne" value="${list.id}"
					 <#if list.id==courses.courseTypeOneId>	checked</#if>>
					<label for="radio-2">${list.coursesType}</label>
				</div>
				<!-- <div class="radio-box">
					<input type="radio"  name="courseTypeOne" value="2"
					<#if courses.courseTypeOneId==2>	checked</#if>>
					<label for="radio-2">色彩</label>
				</div>
				
				<div class="radio-box">
					<input type="radio"  name="courseTypeOne" value="3"
					<#if courses.courseTypeOneId==3>	checked</#if>>
					<label for="radio-2">素描</label>
				</div>
				
				<div class="radio-box">
					<input type="radio"  name="courseTypeOne" value="4"
					<#if courses.courseTypeOneId==4>	checked</#if>>
					<label for="radio-2">速写</label>
				</div> -->
		</#list>
			</div>
		</div>
				<div class="mt-20 skin-minimal">
				<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				是否收费：</label>
				<div class="radio-box">
					<input type="radio" id="isPy-1" name="isPay"
					value="1" <#if courses.isPay==1>	checked</#if>>
					<label for="radio-2">免费</label>
				</div>
				
			
				<div class="radio-box">
					<input type=radio id="isPay-2" name="isPay"
					value="2" onclick="this.form.txt.style.display=''"
					<#if courses.isPay==2>	checked</#if>>
					<label for="radio-1">收费</label>
				</div>


				<div class="mt-20 skin-minimal">
				<label class="form-label col-xs-4 col-sm-2">
					<span class="c-red">*</span>
					共享模式：</label>
					
			<div class="radio-box">
				<input type="radio" id="radio-1" value="1" name="courseShare"
						value=""<#if courses.courseShare==1>	checked</#if>>
				<label for="radio-1">机构专供</label>
			</div>
			<div class="radio-box">
				<input type="radio" id="radio-2" value="2" name="courseShare"
						value="" <#if courses.courseShare==2>	checked</#if>>
				<label for="radio-1">平台共享</label>
			</div>
			<div class="radio-box">
				<input type="radio" id="radio-3" value="3" name="courseShare"
						<#if courses.courseShare==3>	checked</#if>>
				<label for="radio-1">机构内部免费,平台共享收费</label>
			</div>
		</div>


		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				课程简介：</label>
			<div class="formControls col-xs-6 col-sm-6">
			<!-- <textarea  class="textarea radius" placeholder="说点什么..." id="courseintroduction" name="courseintroduction" value="${courses.courseintroduction}" ></textarea> -->
						
				<textarea cols="80" id="content" name="courseintroduction">${courses.courseintroduction}</textarea> 
				<script type="text/javascript">
					window.onload = function() {
						CKEDITOR
								.replace(
										'content',
										{
											filebrowserUploadUrl : path
													+ '/ckeditor/uploader?Type=File&prodId=1111&uploadModel=product',
											filebrowserImageUploadUrl : path
													+ '/ckeditor/uploader?Type=Image&prodId=${1111}&uploadModel=product',
											filebrowserFlashUploadUrl : path
													+ '/ckeditor/uploader?Type=Flash&prodId=${1111}&uploadModel=product'
										});
					}
				</script>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-2">
<input class="btn btn-primary radius" onclick="submitCourses()"
						value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
			</div>
	
	</form>
</div>
<@frame.end "default">
</@frame.end>


<script type="text/javascript">
	function getObjectURL(file) {
		var url = null;
		if (window.createObjectURL != undefined) {
			url = window.createObjectURL(file)
		} else if (window.URL != undefined) {
			url = window.URL.createObjectURL(file)
		} else if (window.webkitURL != undefined) {
			url = window.webkitURL.createObjectURL(file)
		}
		return url
	};

	function imgee(obj) {

		// 上传设置
		var imgObj = getObjectURL(obj.files[0]);//获取图片
		$("#allUrl").attr("src", imgObj);

	}

	function submitCourses() {
		var content = CKEDITOR.instances.content.getData();
		 $("#content").val(content);
		$("#jvForm").ajaxSubmit({
			dataType : 'text',
			success : function(message) {

				if (message == "200") {
					layer.msg('修改成功!', {
						icon : 1,
						time : 1000
					}, function() {
						parent.window.location.reload();
					});
				} else if (message.code == "500") {
					layer.alert(message.message);
				} else if (message == "505") {
					layer.alert("只有老师和机构管理员才能操作!");
				} else if (message == "500") {
					layer.alert(message.message);
					parent.window.location.reload();
				} else {
					layer.alert(message.message);
					parent.window.location.reload();
				}
			},
			error : function() {
				layer.msg('操作失败!', {
					icon : 5,
					time : 1000
				});
			},
			complete : function(XMLHttpRequest, textStatus) {

			}
		});
	}

	function videoSubmit(){
	    $("#upda").ajaxSubmit({
			dataType : 'json',
	        success: function(message){
	        		if(message.code == "200"){
	        			$("#fileVideoName").val(message.message);
	                    layer.msg('上传成功!',{icon:1,time:1000},function(){
	                    });
	 				}else if(message.code == "500"){
	 					layer.alert(message.message);
	 				}else{
	 					layer.alert(message.message);
	 				}
	        },
	        error: function(){
	            layer.msg('操作失败!',{icon:5,time:1000});
	        },complete: function(XMLHttpRequest, textStatus) {
	        	
	        }
	    });
	}

	function fileSelected(file, type) {
		var name = file.name;
		console.log(name);
		var path;
		if (type == "video") {
			path = URL.createObjectURL(file);
			// Todo:视频插件创建错误
			document.getElementById("my-video").src = path;
			var myVideo = document.getElementById("my-video");
			//音量为20%
			myVideo.volume = 0.2;
		}
	}

	function choiceMusicAndVideo(e) {
		fileSelected(e.files[0], "video");
	}
</script>
</body>
</html>